import NotificationService from './notification'

class ReminderService {
  constructor() {
    this.reminders = new Map()
    this.checkInterval = null
  }

  start() {
    // Check for reminders every minute
    this.checkInterval = setInterval(() => {
      this.checkReminders()
    }, 60000)
  }

  stop() {
    if (this.checkInterval) {
      clearInterval(this.checkInterval)
      this.checkInterval = null
    }
  }

  addReminder(id, dateTime, title, message) {
    const reminderTime = new Date(dateTime).getTime()
    this.reminders.set(id, {
      time: reminderTime,
      title,
      message
    })
  }

  removeReminder(id) {
    this.reminders.delete(id)
  }

  checkReminders() {
    const now = Date.now()
    this.reminders.forEach((reminder, id) => {
      if (reminder.time <= now) {
        // Show notification
        // NotificationService.show({
        //   title: reminder.title,
        //   message: reminder.message,
        //   playSound: true
        // })
        // Remove the reminder after it's triggered
        this.removeReminder(id)
      }
    })
  }
}

export default new ReminderService() 